import os
import xml.etree.ElementTree as ET

def is_git_repo(path):
    return os.path.isdir(os.path.join(path, '.git'))

def generate_manifest(base_path):
    root = ET.Element('manifest')
    for dirpath, dirnames, filenames in os.walk(base_path):
        for dirname in dirnames:
            repo_path = os.path.join(dirpath, dirname)
            if is_git_repo(repo_path):
                project = ET.SubElement(root, 'project')
                project.set('path', os.path.relpath(repo_path, base_path))
                project.set('name', dirname)  # 你可以根据需要修改name
                project.set('remote', 'origin')  # 默认remote名称，按需修改
                project.set('revision', 'HEAD')  # 默认revision，按需修改

    tree = ET.ElementTree(root)
    tree.write('default.xml', encoding='utf-8', xml_declaration=True)
    print("Manifest generated as default.xml")

if __name__ == "__main__":
    generate_manifest(os.getcwd())
